package com.leonzx.base.controller.theme;

import com.leonzx.base.controller.base.BaseController;
import com.leonzx.base.entity.system.User;
import com.leonzx.base.service.RedisService;
import com.leonzx.base.service.system.UserService;
import com.leonzx.base.utils.RedisConstants;
import org.redisson.Redisson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author:梁亮
 * @Description:
 * @Date: 2018/7/6 13:57
 */
@RestController
@RequestMapping("/ajax/theme")
public class AjaxThemeController extends BaseController {

    @Autowired
    private UserService userService;

    @Autowired
    private RedisService redisService;

    @RequestMapping("/save")
    public Map<String, Object> edit(User user) {
        Map<String, Object> result = getMap();
        try {
            userService.update(user);
            redisService.setKey(RedisConstants.SHIRO_REDIS_USER_LOGIN_MENU + ":" + currentUser().getUsername(), user.getMenuPosition() + "");
            addSuccessMessage(result, "修改成功");
        } catch (Exception e) {
            addFailMessage(result, "修改失败");
            logger.error("修改失败", e);
        }
        return result;
    }
}
